import sdk from './sdk';

const goodsApi = {

  list() {
    const callback = (reslove, reject) => {
      // 返回正确的结果使用 reslove
      // 返回错误使用 reject 
      setTimeout(() => {
        reslove([{
            goodsList: [{}, {}, {}]
          },
          {
            goodsList: [{}, {}, {}]
          },
          {
            goodsList: [{}, {}, {}]
          },
          {
            goodsList: [{}, {}, {}]
          },
        ])
      }, 1000)
    }
    return new Promise(callback)
  },

  hasStock(goodsId) {
    if (!!goodsId){
      return Promise.reject('商品id不能为空');
      // Promise.resolve('')
    }
    return sdk.get(`/goods/has/stock`, {id: goodsId}).then((resp) => {
      return resp.data;
    })
  },

  async hasStock2(goodsId){
    let resp = await sdk.get(`/goods/has/stock`, {id: goodsId});
    return resp;
  }

};

export default goodsApi;